package com.dbq.fast.business.product.ui;

import android.content.Context;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dbq.fast.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by yh on 2018/3/1.
 */

public class PayTypeItemView extends LinearLayout {
    @BindView(R.id.pay_icon)
    ImageView payIcon;

    @BindView(R.id.pay_name)
    TextView payName;
    @BindView(R.id.checkbox_status)
    ImageView payStatus;

    @BindView(R.id.tip_info)
    TextView tipInfoTv;


    private boolean isCheck = false;

    private int PAY_TYPE = 0;

    public PayTypeItemView(Context context) {
        this(context, null);
    }

    public PayTypeItemView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public PayTypeItemView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        this.setOrientation(LinearLayout.VERTICAL);
        View rootView = LayoutInflater.from(this.getContext()).inflate(R.layout.view_pay_type_item, null);
        ButterKnife.bind(this, rootView);
        this.addView(rootView);

    }

    public void setPayType(int payType) {
        this.PAY_TYPE = payType;
    }

    public int getPayType() {
        return PAY_TYPE;
    }

    public void setStatus(int status) {
        if (status == 0) {//0 为通用状态，1为stripe信用卡支付状态
            tipInfoTv.setVisibility(GONE);
        } else {
            tipInfoTv.setVisibility(GONE);
            payIcon.setVisibility(GONE);
            payName.setVisibility(GONE);
        }
    }

    public void setType(@DrawableRes int iconId, @StringRes int nameId, boolean isCheck) {
        this.isCheck = isCheck;
        payIcon.setBackgroundResource(iconId);
        payName.setText(nameId);
        setPayStatus(isCheck);
    }

    public boolean getCheckStatus() {
        return isCheck;
    }

    public void setPayStatus(boolean isCheck) {
        payStatus.setBackgroundResource(isCheck ? R.drawable.ic_choosed : R.drawable.ic_normal);
    }

    public void setIsVisible(boolean boo) {
        tipInfoTv.setVisibility(boo ? VISIBLE : GONE);
    }
    public void setStripeInfoTv(String text){
        tipInfoTv.setText(text);
    }
}
